##################################################################
# File : /lua/ui/network/network.lua
# Description : Dark Skies networking module
# Author : Neruz
##################################################################

local loginClient = import('/lua/ui/network/loginclient.lua')
local loginServer = import('/lua/ui/network/loginserver.lua')
local dataServer = import('/lua/ui/network/dataserver.lua')
local dataClient = import('/lua/ui/network/dataclient.lua')
local gameClient = import('/lua/ui/network/gameclient.lua')
local gameServer = import('/lua/ui/network/gameserver.lua')

local dataServerPort = 2148
local loginServerPort = 2149
local gameServerPort = 2150

# Everything has it's own lobby comm class because there'll be more differences later on

function GetServerAddress()
	local addr = GetCommandLineArg("/gameserver", 1)[1]
	return addr
end

function CreateLoginServer()
	local comm = loginServer.InitLoginServer("UDP", loginServerPort)
	comm:HostGame()
	return comm
end

function CreateDataServer()
	local comm = dataServer.InitDataServer("UDP", dataServerPort)
	comm:HostGame()
	return comm
end

function CreateDataClient(addr)
	local addr = addr or GetServerAddress() .. ":" .. tostring(dataServerPort)
	local comm = dataClient.InitDataClient("UDP")
	comm:JoinGame(addr, "dataServer", 0)
	return comm
end

function CreateGameServer()
	local comm = gameServer.InitGameServer("UDP", gameServerPort)
	comm:HostGame()
	return comm
end

function CreateLoginClient(addr)
	local addr = addr or GetServerAddress() .. ":" .. tostring(loginServerPort)
	local comm = loginClient.InitLoginClient("UDP")
	comm:JoinGame(addr, "loginServer", 0)
	return comm
end

function CreateGameClient(addr)
	local addr = addr or GetServerAddress() .. ":" .. tostring(gameServerPort)
	local comm = gameClient.InitGameClient("UDP")
	comm:JoinGame(addr, "gameServer", 0)
	return comm
end